class Pocker extends egret.DisplayObjectContainer {
    private isDragon: boolean = true;

    private back: egret.Bitmap;
    private frontBg: egret.Bitmap;


    public constructor(isDragon: boolean) {
        super();
        this.isDragon = isDragon;
        this.width =175;
        this.height =283;
        this.onCreate();
    }

    protected onCreate(): void {
        if (this.isDragon) {
            this.back = new egret.Bitmap(RES.getRes("dragon_png"));
            this.frontBg = new egret.Bitmap(RES.getRes("lb_png"));
        } else {
            this.back = new egret.Bitmap(RES.getRes("tiger_png"));
            this.frontBg = new egret.Bitmap(RES.getRes("hb_png"));
        }
        this.addChild(this.back);
        this.addChild(this.frontBg);
        this.frontBg.visible = false;
    }

    public startRotate(): void {
        egret.Tween.get(this).to({ scaleX: .7, scaleY: .7 }, 300, egret.Ease.circIn);
        var tw1 = egret.Tween.get(this, { loop: true });
        tw1.to({ scaleX: 0.01 }, 80).to({ scaleX: .7 }, 80);
    }
    public stopRotate(): void {
        egret.Tween.removeTweens(this);
        egret.Tween.get(this).to({ scaleX: .7, scaleY: .7 }, 300, egret.Ease.circIn);
    }

    private leftTop: Pattern;
    private rightBottom: Pattern;
    
    public showFront(pattern: PokerPattern, num: number): void {

        this.leftTop = new Pattern(pattern, num);
        this.rightBottom = new Pattern(pattern, num);
        this.rightBottom.rotation = 180;

        this.leftTop.x = 0;
        this.leftTop.y = 0;
        this.rightBottom.x = this.back.width;
        this.rightBottom.y = this.back.height;
        this.addChild(this.leftTop);
        this.addChild(this.rightBottom);
        this.back.visible = false;
        this.frontBg.visible = true;
    }

    public showBg(): void {
        if (this.leftTop && this.contains(this.leftTop)) {
            this.removeChild(this.leftTop);
        }
        if (this.rightBottom && this.contains(this.rightBottom)) {
            this.removeChild(this.rightBottom);
        }
        this.back.visible = true;
        this.frontBg.visible = false;
    }
}